<?php session_start();
if(@$_SESSION["Username"]) {
	$user = $_SESSION["Username"];
	
	require_once 'config.php';
	
	require_once DIR.'class.sql.php';
	$sql = new sql();
	
	if(@$_POST['delete']){
		$type = 3;
		$table = $_POST['page'];
		$id = $_POST['id'];
		$sql->get_sql($type,$table,$user,$id);
		$sql->executable();
	}
	
	if(isset($_POST['KiemTraUser'])) {
		$user = $_POST['KiemTraUser'];
		$total = mysql_result($qt->Users_KiemTraUser($user),0);
		if($total == 0 & eregi("^[[:alnum:]]+$", $user)) echo '<font color="#00CC00">Username hợp lệ</font>'; else echo '<font color="#FF0000">Username đã tồn tại hoặc có ký tự đặc biệt</font>';
	}
	
	if(@$_POST['lophoc_id']){
		echo "<option value=''>-- Chọn học viên --</option>s";
		if($_POST['mahv']=='' && $_POST['mahv']==0){
			$qr = mysql_query("SELECT id, concat(id,' | ',ho,' ',ten) as hoten FROM hocvien WHERE lophoc_id='{$_POST['lophoc_id']}' AND id not in (SELECT hocvien_id FROM ".$_SESSION['page']." WHERE lophoc_id='{$_POST['lophoc_id']}') ORDER BY id");
			while($row = mysql_fetch_array($qr)){
				echo "<option value='{$row['id']}'>{$row['hoten']}</option>";
			}
			mysql_free_result($qr);
		}else{
			$qr = mysql_query("SELECT id, concat(id,' | ',ho,' ',ten) as hoten FROM hocvien WHERE lophoc_id='{$_POST['lophoc_id']}' ORDER BY id");
			while($row = mysql_fetch_array($qr)){
				if($_POST['mahv'] != $row['id']) echo "<option value='{$row['id']}'>{$row['hoten']}</option>"; else echo "<option value='{$row['id']}' selected='selected'>{$row['hoten']}</option>";
				//echo "<option value='{$row['id']}'>{$row['hoten']}</option>";
			}
			mysql_free_result($qr);
		}
	}
	
	/*if(@$_POST['export_excel']){
		require_once('library/export_excel/php-excel.class.php');
		$data = array( 
				1 => array ('Name', 'Trần Hiếu Nhân'), 
					 array('Schwarz', 'Lâm Dưỡng'), 
					 array('Test', 'Peter') 
				); 

		// generate file (constructor parameters are optional) 
		$xls = new Excel_XML('UTF-8', false, 'Workflow Management'); 
		$xls->addArray($data); 
		$xls->generateXML('Output_Report_WFM');
	}*/
}
?>